/*
 * 文件名称: RpcInvocationHandler.java Copyright 2011-2016 Ximalaya All right reserved.
 */
package top.zxybird.yun.rpc.api;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import com.google.common.reflect.AbstractInvocationHandler;

/**
 * for both client and server
 *
 * @author Ted Wang
 */
public class RpcInvocationHandler implements InvocationHandler {

  private Invoker invoker;

  public RpcInvocationHandler(Invoker invoker) {
    this.invoker = invoker;
  }

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

    // 1. 将method和args转化成Invocation
    Invocation invocation = new Invocation(method, args);
    // 调用invoker
    return invoker.invoke(invocation).get();
  }

}